<?php

namespace App\Models\Member;

use App\Models\BaseModel;

class AccessToken extends BaseModel
{
    protected $fillable = [
        'id', 'store_id', 'access_token', 'expire_at', 'ticket', 'ticket_at',
        'created_at', 'updated_at'
    ];

    public function insertData($storeId, $data)
    {
        $expireAt = date("Y-m-d H:i:s", strtotime("+{$data['expires_in']} second"));
        $accessToken = $data['access_token'];
        $arr = [
            'store_id' => $storeId,
            'access_token' => $data['access_token'],
            'expire_at' => $expireAt
        ];
        $data = $this->create($arr);
        return $data->toArray();
    }

    public function updateData($id, $data)
    {
        $expireAt = date("Y-m-d H:i:s", strtotime("+{$data['expires_in']} second"));
        $accessToken = $data['access_token'];
        $arr = [
            'access_token' => $data['access_token'],
            'expire_at' => $expireAt
        ];
        $this->find($id)->update($arr);
        return $this->find($id)->toArray();
    }
}
